﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using School;

namespace TestSchool
{
    [TestClass]
    public class TestCourse
    {
        [TestMethod]
        public void Course_TestCourseNameInConstructorNotNull()
        {
            string name = "KPK";
            List<Student> students = new List<Student>();
            Course course = new Course(name, students);
            Assert.IsNotNull(course.NameOfCourse, "The name of the course can not be null!");
        }

        [TestMethod]
        public void Course_TestNumberOfStudentsInCourse()
        {
            string name = "KPK";
            byte maxCount = 29;
            List<Student> students = new List<Student>();
            bool isInRange = students.Count <= maxCount;
            Course course = new Course(name, students);
            Assert.IsTrue(isInRange, "The number of the students in one course can not be more than " + maxCount + " !");
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void Course_TestCountOfStudentsIsInRange()
        {
            List<Student> students = new List<Student>();
            Student student = new Student("Ivo", 32412);
            for (var i = 0; i < 31; i++)
            {
                students.Add(student);
            }
            Course course = new Course();
            course.Students = students;
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void Course_TestCourseNameNotNull()
        {
            Course course = new Course();
            course.NameOfCourse = null;
        }

        /////
        [TestMethod]
        public void AddStudentTestOneStudent()
        {
            string name = "Javascript";
            List<Student> students = new List<Student>();
            Course course = new Course(name, students);
            Student maria = new Student("Maria Petrova", 12345);
            course.AddStudent(maria);
            Assert.IsTrue(course.Students.Count == 1);
        }

        [TestMethod]
        public void AddStudentTestTwoStudents()
        {
            string name = "Javascript";
            List<Student> students = new List<Student>();
            Course course = new Course(name, students);
            Student maria = new Student("Maria Petrova", 12345);
            Student petar = new Student("Petar Marinov", 23445);
            course.AddStudent(maria);
            course.AddStudent(petar);
            Assert.IsTrue(course.Students.Count == 2);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void AddStudentTestSameStudentTwoTimes()
        {
            string name = "Javascript";
            List<Student> students = new List<Student>();
            Course course = new Course(name, students);
            Student maria = new Student("Maria Petrova", 12345);
            course.AddStudent(maria);
            course.AddStudent(maria);
        }

        [TestMethod]
        public void RemoveStudentTest()
        {
            string name = "Javascript";
            List<Student> students = new List<Student>();
            Course course = new Course(name, students);
            Student maria = new Student("Maria Petrova", 12345);
            Student petar = new Student("Petar Marinov", 23445);
            course.AddStudent(maria);
            course.AddStudent(petar);
            course.RemoveStudent(petar);
            Assert.IsTrue(course.Students.Count == 1);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void RemoveNonExistingStudentTest()
        {
            string name = "Javascript";
            List<Student> students = new List<Student>();
            Course course = new Course(name, students);
            Student maria = new Student("Maria Petrova", 12345);
            course.RemoveStudent(maria);
        }
    }
}
